using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;

namespace ClassLibrary1.Models.Mapping
{
    public class Bs_DepartmentMap : EntityTypeConfiguration<Bs_Department>
    {
        public Bs_DepartmentMap()
        {
            // Primary Key
            this.HasKey(t => t.DId);

            // Properties
            this.Property(t => t.DName)
                .HasMaxLength(50);

            this.Property(t => t.DTel)
                .HasMaxLength(20);

            this.Property(t => t.DFax)
                .HasMaxLength(20);

            this.Property(t => t.DFunction)
                .HasMaxLength(20);

            this.Property(t => t.DMemo)
                .HasMaxLength(200);

            // Table & Column Mappings
            this.ToTable("Bs_Department");
            this.Property(t => t.DId).HasColumnName("DId");
            this.Property(t => t.DName).HasColumnName("DName");
            this.Property(t => t.DTel).HasColumnName("DTel");
            this.Property(t => t.DFax).HasColumnName("DFax");
            this.Property(t => t.DParentID).HasColumnName("DParentID");
            this.Property(t => t.DCompanyId).HasColumnName("DCompanyId");
            this.Property(t => t.DManagerId).HasColumnName("DManagerId");
            this.Property(t => t.DFunction).HasColumnName("DFunction");
            this.Property(t => t.DFlag).HasColumnName("DFlag");
            this.Property(t => t.DSortNo).HasColumnName("DSortNo");
            this.Property(t => t.DMemo).HasColumnName("DMemo");

            // Relationships
            this.HasOptional(t => t.Bs_Company)
                .WithMany(t => t.Bs_Department)
                .HasForeignKey(d => d.DCompanyId);

        }
    }
}
